<script setup lang="ts">
import GrandsonCom from '@/components/grandsonCom.vue'
import { inject } from 'vue'

const msg: string = '子组件内容'

function getMsg() {
  console.log(msg)
}

defineExpose({ msg, getMsg })

// 获取不到祖先的数据
const info = inject('toGrandKey', '这是子组件') // 验证数据是否能到达子组件
console.log(info)

</script>

<template>
  <h1>这是儿子组件</h1>
  <p>从父组件接收到的信息：{{ info }}</p>
  <GrandsonCom></GrandsonCom>
  <p>son {{ msg }}</p>
</template>

<style scoped></style>
